proc userdel {nick handle chan otbn1 otbn host} {
  global botnick home bcast

  if {![matchattr $handle o|m $chan]} {
    putquick "NOTICE $nick :\0034Unable To Execute Command - Permission Denied\003."
    return 0
  } elseif {$otbn1 == ""} {
    putquick "NOTICE $nick :\0034ERROR - Should Be - \002(/msg) $botnick userdel <#channel> <nick>"
    return 0
  } 

  if {[validuser $otbn1]} {
    set hand2 $otbn1
  } elseif {[onchan $otbn1 $chan]} {
    set hand2 [nick2hand $otbn1 $chan]
  } else {
    putquick "NOTICE $nick :\0034ERROR - \002$otbn1\002 does not appear to have any access to this bot at all therefore they cannot be removed from this bot\003."
    return 0
  }

  if {$hand2 == $handle} {
    putquick "NOTICE $nick :\0034ERROR - Unable to userdel user with equal or more access than you.  You must find with higher access than that user to have them removed\003."
    return 0
  }

  if {$otbn == "global"} {
    if {![matchattr $handle m]} {
      putquick "NOTICE $nick :\0034ERROR - Permission Denied"  	  
      return 0
    }

    if {[checkaccess $handle $chan $hand2]} {
      deluser $hand2
      putlog "!$nick ($host)! userdel $hand2 global"
      putquick "NOTICE $nick :\0033Sucessfully, completely and globally userdel'd '\002\0034$otbn1\002\0033'" 

      if {$bcast == "1"} {
	  putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to userdel \002$hand2\002 (No Exemptions.)"
	}

      return 0
    } else {
      putquick "NOTICE $nick :\0034ERROR - Permission Denied\003."
      putquick "NOTICE $otbn1 :\0034WARNING - \002$nick\002 ($host) tried to userdel you globally\003."	    

      if {$bcast == "1"} {
	  putquick "PRIVMSG $home :\002$nick\002 ($host) tried to userdel \002$hand2\002 - permission was denied\003."
      }

      return 0
    }
  }

  if {![checkaccess $handle $chan $hand2]} {
    putquick "NOTICE $nick :\0034ERROR - Permission Denied\003."
    putquick "NOTICE $otbn1 :\0034WARNING - \002$nick\002 ($host) tried to userdel you in $chan"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) tried to userdel \002$otbn1\002 on $chan and $nick is a lower user\003."
    }

    return 0
  }

  if {![delchanrec $hand2 $chan]} {
    putquick "NOTICE $nick :\0034ERROR - $otbn1 does not appear to have access in '\002$chan\002'"
    return 0 
  }

  foreach channel [channels] {
    if {[matchattr $hand2 |f $channel]} {
      putlog "!nick ($host)! userdel $chan $hand2"
      putquick "NOTICE $nick :\0033Successfully userdel'd \0034$otbn1\0033 on \0034$chan"

      if {$bcast == "1"} {
        putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to userdel \002$hand2\002 in channel record '$chan'"
      }

      return 0
    }
  }

  if {[matchattr $hand2 f]} {
    putlog "!$nick ($host)! userdel $chan $hand2" 
    putquick "NOTICE $nick :\0033Successfully userdel'd \0034$otbn1\0033 on \0034$chan"	

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to userdel \002$hand2\002 in channel record '$chan'"
    }

    return 0
  }

  deluser $hand2
  putlog "!$nick ($host)! userdel $chan $hand2"
  putquick "NOTICE $nick :\0033Successfully userdel'd \00312$otbn1\0033 on \0034$chan"    

  if {$bcast == "1"} {
    putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to userdel \002$hand2\002 in channel record '$chan'"
  }  
}

